package cn.picclife.mwx.common.core.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author Levi.Wang
 * 日志记录工具类
 */
public class LogUtils {

	public static final Logger ERROR_LOG = LoggerFactory.getLogger("error");
	public static final Logger ACCESS_LOG = LoggerFactory.getLogger("access");

	public static void logAccess(String... obj) {
		StringBuilder s = new StringBuilder();
		for (String logFiled : obj)
			s.append(getBlock(logFiled));
		
		getAccessLog().info(s.toString());
	}

	/**
	 * 记录异常错误 格式 [exception]
	 *
	 * @param message
	 * @param e
	 */
	public static void logError(String message, Throwable e) {
		StringBuilder s = new StringBuilder();
		s.append(getBlock("exception"));
		s.append(getBlock(message));
		ERROR_LOG.error(s.toString(), e);
	}

	public static String getBlock(Object msg) {
		if (msg == null) {
			msg = "";
		}
		return "[" + msg.toString() + "]";
	}

	
	public static Logger getAccessLog() {
		return ACCESS_LOG;
	}

	public static Logger getErrorLog() {
		return ERROR_LOG;
	}

}
